//
//  RecordingTableViewCell.swift
//  AreaChainblock
//
//  Created by 赵佟越 on 2018/9/26.
//  Copyright © 2018年 zhaotongyue. All rights reserved.
//

import UIKit

class RecordingTableViewCell: UITableViewCell {
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var mybackview: UIView!
    @IBOutlet weak var moneyLabel: UILabel!
    @IBOutlet weak var typeLabel: UILabel!
    private var myModel:productModel? = productModel()
    var isFrom :String!
    var isMN :String!
    var model :productModel{
        set {
            myModel = newValue;
            if newValue.m != nil{
                myModel?.m =
                    String(format: "%.3f", Float(newValue.m as String!)!)
            }
            if newValue.n != nil{
                myModel?.n =
                    String(format: "%.3f", Float(newValue.n as String!)!)
            }
            if newValue.dke != nil{
                myModel?.dke =
                    String(format: "%.3f", Float(newValue.dke as String!)!)
            }

            if isFrom == "1"{
                myModel?.dke =
                    String(format: "%.3f", Float(newValue.dke as String!)!)
                
                if isMN == "1"{
                    //moneyLabel.text = String(format:"- %@ cd   + %@ dke",(myModel?.m)!, (myModel?.dke)!)
                    if myModel?.type == "1"{
                        //锁
                        let attrMStr = NSMutableAttributedString()
                        let attacmentM_baozhi = NSTextAttachment()
                        attacmentM_baozhi.image = UIImage(named: "锁@2x")
                        attacmentM_baozhi.bounds = CGRect(x: 5, y: 0, width: 12, height: 12)
                        
                        var attrMStrbaozhi : NSAttributedString = NSAttributedString(string: "")
                        attrMStrbaozhi = NSAttributedString(string: String(format:"%@   + %@ dke",XALanguageManager.getString(key: "") ,(myModel?.dke)!))
                        
                        var attrMStrbaozhi1 : NSAttributedString = NSAttributedString(string: "")
                        attrMStrbaozhi1 = NSAttributedString(string: String(format:"%@     - %@ cd  ",XALanguageManager.getString(key: "") ,(myModel?.m)!))
                        let attacmentM_baozhi2 = NSAttributedString(attachment: attacmentM_baozhi)
                        attrMStr.append(attrMStrbaozhi1)
                        attrMStr.append(attacmentM_baozhi2)
                        attrMStr.append(attrMStrbaozhi)
                        
                        moneyLabel.attributedText = attrMStr
                        
                        
                        
                    }else{
                        moneyLabel.text = String(format:"- %@ cd   + %@ dke",(myModel?.m)!, (myModel?.dke)!)
                    }
                    
                    
                    
                }else{
                    moneyLabel.text = String(format:"- %@ mt   + %@ dke",(myModel?.n)!, (myModel?.dke)!)
                }
                
                
                
                timeLabel.text = String(format:"%@  ",XALanguageManager.getString(key: (myModel?.create_time!)!))
                timeLabel.sizeToFit()
                timeLabel.textColor = UIColor.white
                
                
            moneyLabel.adjustsFontSizeToFitWidth = true
                moneyLabel.textAlignment = .right
                
                
                
                moneyLabel.textColor = UIColor.white
                typeLabel.adjustsFontSizeToFitWidth = true
                typeLabel.font = UIFont.systemFont(ofSize: 16)
                mybackview.backgroundColor = UIColor.clear
                
                typeLabel.text = XALanguageManager.getString(key: "")
            }else{
                
//                timeLabel.text = String(format:"%@  %@",XALanguageManager.getString(key: (myModel?.month!)!),(myModel?.day)!)
                timeLabel.text = String(format:"%@  ",XALanguageManager.getString(key: (myModel?.create_time!)!))
                timeLabel.sizeToFit()
                timeLabel.adjustsFontSizeToFitWidth = true
                moneyLabel.adjustsFontSizeToFitWidth = true
                moneyLabel.textColor = UIColor.white
                moneyLabel.textAlignment = .right
                timeLabel.textColor = UIColor.white
                typeLabel.textColor = UIColor.white
                mybackview.backgroundColor = UIColor.clear
                
                
                typeLabel.adjustsFontSizeToFitWidth = true
                typeLabel.font = UIFont.systemFont(ofSize: 16)
                typeLabel.text = XALanguageManager.getString(key: "")

                if myModel?.type == "1"{
                    if isFrom == "M" {
                        moneyLabel.text = String(format:"%@     + %@ cd",XALanguageManager.getString(key: "充能获得"), (myModel?.m)!)
                    }else if isFrom == "N"{
                        moneyLabel.text = String(format:"%@     + %@ mt",XALanguageManager.getString(key: "充能获得") ,(myModel?.n)!)
                    }else{
                        //新增status
                        if myModel?.status == "0"{
                            moneyLabel.text = String(format:"%@-%@      %@ dke",XALanguageManager.getString(key: "转入"),XALanguageManager.getString(key: "待确定"), (myModel?.dke)!)
                        }else if myModel?.status == "1"{
                            moneyLabel.text = String(format:"%@-%@     + %@ dke",XALanguageManager.getString(key: "转入"),XALanguageManager.getString(key: "成功"), (myModel?.dke)!)
                        }else if myModel?.status == "-1"{
                            moneyLabel.text = String(format:"%@-%@      %@ dke",XALanguageManager.getString(key: "转入"),XALanguageManager.getString(key: "失败"), (myModel?.dke)!)
                        }else{
                            moneyLabel.text = String(format:"%@     + %@ dke",XALanguageManager.getString(key: "转入"), (myModel?.dke)!)
                        }
                    }
//                    typeLabel.text = XALanguageManager.getString(key: "Transfer")
                }else if myModel?.type == "2"{
                    if isFrom == "M" {
                        moneyLabel.text = String(format:"%@     - %@ cd",XALanguageManager.getString(key: "挖矿消耗"), (myModel?.m)!)
                    }else if isFrom == "N"{
                        moneyLabel.text = String(format:"%@     - %@ mt",XALanguageManager.getString(key: "挖矿消耗") ,(myModel?.n)!)
                    }else{
                        if myModel?.status == "0"{
                            moneyLabel.text = String(format:"%@-%@     - %@ dke",XALanguageManager.getString(key: "转出"),XALanguageManager.getString(key: "待确定"), (myModel?.dke)!)
                        }else if myModel?.status == "1"{
                            moneyLabel.text = String(format:"%@-%@     - %@ dke",XALanguageManager.getString(key: "转出"),XALanguageManager.getString(key: "成功"), (myModel?.dke)!)
                        }else if myModel?.status == "-1"{
                            moneyLabel.text = String(format:"%@-%@     + %@ dke",XALanguageManager.getString(key: "转出"),XALanguageManager.getString(key: "失败"), (myModel?.dke)!)
                        }else{
                            moneyLabel.text = String(format:"%@     - %@ dke",XALanguageManager.getString(key: "转出"), (myModel?.dke)!)
                        }
                    }
                }
                else{
                    if isFrom == "M" {
                        moneyLabel.text = String(format:"%@      %@ cd",XALanguageManager.getString(key: "???"), (myModel?.m)!)
                    }else if isFrom == "N"{
                        moneyLabel.text = String(format:"%@     + %@ mt",XALanguageManager.getString(key: "推广获得") ,(myModel?.n)!)
                    }else{
                        
                        if myModel?.type == "4"{
                            moneyLabel.text = String(format:"%@     - %@ dke",XALanguageManager.getString(key: "保值清算"), (myModel?.dke)!)
                        }else if myModel?.type == "5"{
                            moneyLabel.text = String(format:"%@     - %@ dke",XALanguageManager.getString(key: "挖矿所得"), (myModel?.dke)!)
                        }else if myModel?.type == "6"{
                            moneyLabel.text = String(format:"%@     + %@ dke",XALanguageManager.getString(key: "昨日加息"), (myModel?.dke)!)
                        }else{
                            moneyLabel.text = String(format:"%@     - %@ dke",XALanguageManager.getString(key: "充能消耗"), (myModel?.dke)!)
                        }
                        
                    }
//                    typeLabel.text = XALanguageManager.getString(key: "Transfer out")
                }
            }
            
            
            
        }
        get
        {
            return (self.myModel)!
            
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        self.contentView.backgroundColor = UIColor.clear
        let LineView = UIView(frame: CGRect(x: 15, y: 39, width: kScreenWidth - 30, height: 1))
        LineView.backgroundColor = UIColor("#293163")
        
        self.contentView.addSubview(LineView)
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    
    
}
